import { createApp } from 'vue';
import ArcoVue from '@arco-design/web-vue';
import ArcoVueIcon from '@arco-design/web-vue/es/icon';

import NProgress from 'nprogress'; // progress bar
// import globalComponents from '@/components';
// import Barcode from '@/components/Barcode/index.vue';
// import QRCode from 'qrcode';
import print from 'vue3-print-nb';
import router from './router';
import store from './store';
// import i18n from './locale';
import directive from './directive';
// import './mock';
import App from './App.vue';
import '@arco-design/web-vue/dist/arco.css';
import '@/assets/style/global.less';
// eslint-disable-next-line import/order
// import JsBarcode from 'jsbarcode';

// import '@/api/interceptor';

const app = createApp(App);

// app.config.globalProperties.jsbarcode = JsBarcode;
// app.component('Barcode', Barcode);
app.use(print);
app.use(ArcoVue, {});
app.use(ArcoVueIcon);
app.use(router);
app.use(store);
// app.use(JsBarcode);
// app.use(i18n);
// app.use(globalComponents);
// app.config.globalProperties.jsbarcode = JsBarcode;
app.use(directive);

app.mount('#app');
// 自定义指令
app.directive('focus', {
  mounted(el) {
    el.focus();
  }
});

app.directive('enterNumber', {
  mounted(el, { value = 100 }, vnode) {
    el = el.name === 'INPUT' ? el : el.children[0];
    let RegStr =
      value === 0
        ? `^[\\+\\-]?\\d+\\d{0,0}`
        : `^[\\+\\-]?\\d+\\.?\\d{0,${value}}`;
    el.addEventListener('input', function () {
      el.value = el.value.match(new RegExp(RegStr, 'g'));
      el.dispatchEvent(new Event('input'));
    });
  }
});

NProgress.configure({ showSpinner: true }); // NProgress Configuration
